﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using Acsys.Entity;
using MySql.Data.MySqlClient;

namespace Acsys
{
    public class TransactionRepository : Repository
    {
        public TransactionRepository()
            : base()
        {
        }
        public string GetNextNo(ITransaction e)
        {
            string result = "";
            try
            {
                OpenConnection();
                MySqlCommand aCommand = new MySqlCommand(e.GetMaximumNoSQL(), m_connection);
                object r = aCommand.ExecuteScalar();
                int maxNo = r is System.DBNull ? 0 : Convert.ToInt32(r);
                maxNo++;
                result = maxNo.ToString().PadLeft(3,'0');
                result = result + "/BLL-BTM/" + DateTime.Today.Month.ToString().PadLeft(3,'0') + "/" + DateTime.Today.Year.ToString();
                return result;
            }
            catch (Exception x)
            {
                throw new Exception(getErrorMessage(x));
            }
            finally
            {
                m_connection.Close();
            }
        }
    }
}
